home *** CD-ROM | disk | FTP | other *** search
- Path: cs.tu-berlin.de!news
- From: Roman Lechtchinsky <wolfro@cs.tu-berlin.de>
- Newsgroups: comp.lang.c
- Subject: Re: Problem with a for loop
- Date: 2 Mar 1996 16:31:09 GMT
- Organization: Technical University of Berlin, Germany
- Message-ID: <4h9t4d$gjl@news.cs.tu-berlin.de>
- NNTP-Posting-Host: 130.149.17.226
- Mime-Version: 1.0
- Content-Type: text/plain; charset=iso-8859-1
- Content-Transfer-Encoding: 8bit
-
- ksexton@wilde.oit.umass.edu (Kevin M Sexton) writes:
- > Hi.
- > I was doing a project for one of my classes and I came across a rather
- > odd bug in part of the code. I initially had the following:
- > for ( i = 0; WL[i] != NULL, i <= 10; i++ )
- > {
- > AAL[i] = new char[strlen(WL[i])+1);
- > strcpy(AAL[i], WL[i]);
- > }
- >
-
- You have to change your condition to WL[i]!=NULL && i<=10. The comma
- operator evaluates the first expression( WL[i]!=NULL ), then the second
- ( i<=10 ) and return the value of the second. Thus, you loop is always
- executed until i==11.
-
- Bye
-
- Roman
-